package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC746 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int minCostClimbingStairs(int[] cost) {
            if (cost.length <= 1) return cost[0];

            int[] dp = new int[cost.length];
            dp[0] = cost[0];
            dp[1] = cost[1];

            for (int i = 2; i < cost.length; i++) {
                dp[i] = Math.min(dp[i - 1], dp[i - 2]) + cost[i];
            }

            return Math.min(dp[cost.length - 1], dp[cost.length - 2]);
        }
    }

    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[0,0,0,1]");
        System.out.println(solution.minCostClimbingStairs(arr));
    }

    public static void main(String[] args) throws Exception {
        LC746 an = new LC746();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
